//
//  HSForumListCell.m
//  HolyShit
//
//  Created by Robin on 2017/4/4.
//  Copyright © 2017年 HolyShit. All rights reserved.
//

#import "HSForumListCell.h"

@interface HSForumListCell ()

@property (nonatomic, strong) UIImageView *iconImgV;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *descLb;
@property (nonatomic, strong) UIButton *btn;

@end

@implementation HSForumListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self commonInit];
    }
    return self;
}

- (void)commonInit
{
    self.backgroundColor = WHITE_COLOR;
    self.width = ScreenWidth;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (ForumListStyle == 1) {
        self.iconImgV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 40, 40) imageType:MYImageTypeSmallPic];
        self.iconImgV.layer.cornerRadius = 20;
        [self addSubview:self.iconImgV];
        [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10);
            make.left.mas_equalTo(10);
            make.width.height.mas_equalTo(40);
        }];
        self.btn = [UIButton buttonWithFrame:CGRectMake(0, 0, 0, 0) font:MYFont(Font30) color:HEXCOLOR(appNavColor) title:@"进入圈子"];
        self.btn.userInteractionEnabled = NO;
        [self addSubview:self.btn];
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.iconImgV);
            make.right.mas_equalTo(-10);
            make.width.mas_equalTo(80);
            make.height.mas_equalTo(30);
        }];
        self.btn.layer.cornerRadius = 15;
        self.btn.layer.borderWidth = 1;
        self.btn.layer.borderColor = HEXCOLOR(appNavColor).CGColor;
        
        self.nameLb = [UILabel labelWithFont:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
        [self addSubview:self.nameLb];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconImgV);
            make.left.equalTo(self.iconImgV.mas_right).offset(10);
            make.right.equalTo(self.btn.mas_left).offset(-10);
        }];
        
        self.descLb = [UILabel labelWithFont:MYFont(Font28) color:HEXCOLOR(HSColorGray)];
        [self addSubview:self.descLb];
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.iconImgV);
            make.left.right.equalTo(self.nameLb);
        }];
        [self showLineForDirection:MYDirectionBottom];
    }
    else{
        self.iconImgV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 50, 50) imageType:MYImageTypeSmallPic];
        self.iconImgV.layer.cornerRadius = 25;
        [self addSubview:self.iconImgV];
        [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10);
            make.left.mas_equalTo(15);
            make.width.height.mas_equalTo(50);
        }];
        self.nameLb = [UILabel labelWithFont:MYFont(Font32) color:HEXCOLOR(HSColorBlack)];
        [self addSubview:self.nameLb];
        [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.iconImgV).offset(5);
            make.left.equalTo(self.iconImgV.mas_right).offset(10);
            make.right.mas_offset(-10);
        }];
        
        self.descLb = [UILabel labelWithFont:MYFont(Font26) color:HEXCOLOR(HSColorRed)];
        [self addSubview:self.descLb];
        [self.descLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.iconImgV).offset(-5);
            make.left.right.equalTo(self.nameLb);
        }];
        [self showLineForDirection:MYDirectionBottom leftPad:70];
    }
}

- (void)setModel:(HSForumListModel *)model
{
    _model = model;
    UIImage *img = [UIImage imageNamed:model.attributes.name];
    if (!img) {
        img = [UIImage imageNamed:[NSString stringWithFormat:@"%@.jpg", model.attributes.name]];
    }
    if (!img) {
        img = [UIImage imageWithColor:[UIColor colorWithHexString:model.attributes.color]];
    }
    self.iconImgV.image = img;
    self.nameLb.text = model.attributes.name;
    self.descLb.text = model.attributes.desc;
}

@end
